<?php
	require_once 'Model/FileUploadModel.php';

	require_once 'View/FileUploadView.php';
	
	class FileUploadController{
		private $m_loginHandler = NULL;
		private $SaveFileFolder = "uploads/";
		
		public function __construct(LoginHandler $loginHandler){
			$this->m_loginHandler = $loginHandler;
		}
		public function DoControl(){
					
			$body = "";		
							
			$fileUploadView = new FileUploadView();
			$fileUploadModel = new FileUploadModel();
						
			// Är användaren inloggad?
			if ($this->m_loginHandler->IsLoggedIn()) {
				// Om användaren har klickat på 'Ladda upp'
				if ($fileUploadView->TriedToUpload() == TRUE) {
					if($fileUploadView->HasFile() == TRUE){
						if($fileUploadModel->SaveFile($fileUploadView->GetFileInfo()) == FALSE){
							$body .= $fileUploadView->uploadFailed();
						}else{
							$body .= $fileUploadView->uploadSucceeded();
						}
					}
				}
				$body .= $fileUploadView->DoUploadForm();
			}
			$body .= $fileUploadView->ShowFiles($fileUploadModel->GetFiles());
			
			$page = new Page();
			$page->body = $body;
			$page->title = "titel BYT";
			
			
			return $page;					
		}
		


 	}
